/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon
 												
Class							:				UnitTypeAtSoftCondition
 
Function						: 				Provides a class for holding a 
												condition that specifies whether 
												a unit exists at a particular location
****************************************************************************/

package planninglanguage.softconditions;

import base.WargusGameState;
import base.WargusPlayer;
import base.WargusStateImporter;
import base.WargusUnit;


public class UnitTypeAtSoftCondition extends SoftCondition {

	int m_playerID;
	String m_unitType;
	int m_x;
	int m_y;
	
	public UnitTypeAtSoftCondition(String a_unitType,int a_x,int a_y,int a_playerID)
	{
		m_playerID = a_playerID;
		m_unitType =  a_unitType;
		m_x=a_x;
		m_y=a_y;
	}
	
	public String toString(int tabs) {
		String n = super.toString(tabs);
		n = n+ "Player Id is:" + m_playerID;
		n = n + "Unit Type is" + m_unitType;
		n = n + "X coordinate is" + m_x;
		n = n + "Y coordinate is" + m_y;
		
		return n;
	}	
	
	public float test(WargusGameState a_gameState)
	{
		for(WargusUnit u:a_gameState.getPlayer().getUnits()) {
			if (u.getLocX() == m_x && u.getLocY() == m_y &&
				WargusStateImporter.unitTypeToString(u.getType()).equals(m_unitType)) return 1.0f;	
		}
		
		for(WargusPlayer p:a_gameState.getOpponent()) {
			for(WargusUnit u:p.getUnits()) {
				if (u.getLocX() == m_x && u.getLocY() == m_y &&
					WargusStateImporter.unitTypeToString(u.getType()).equals(m_unitType)) return 1.0f;	
			}
		}
		
		return 0.0f;
	}
}
